package cn.wit.summit.chwan.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.wit.summit.chwan.R;

/**
 * Created by tangbl on 2018/04/18.
 */

public class SearchHotAdapter extends BaseAdapter {

    private List<String> mList;
    private Context context;

    public SearchHotAdapter(Context context, List<String> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public String getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search_hot_view, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (position==0)
            viewHolder.itemSearchHotTitleLl.setVisibility(View.VISIBLE);
        else
            viewHolder.itemSearchHotTitleLl.setVisibility(View.GONE);

        if (position<3) {
            viewHolder.itemSearchHotNumTx.setText((position+1)+".");
            viewHolder.itemSearchHotNumTx.setVisibility(View.VISIBLE);
        } else {
            viewHolder.itemSearchHotNumTx.setVisibility(View.GONE);
        }

        viewHolder.itemSearchHotTx.setText(mList.get(position));

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.itemSearchHotTitleLl)
        LinearLayout itemSearchHotTitleLl;
        @Bind(R.id.itemSearchHotNumTx)
        TextView itemSearchHotNumTx;
        @Bind(R.id.itemSearchHotTx)
        TextView itemSearchHotTx;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
